package com.lzw.bluetoothpractice.Activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;

import com.lzw.bluetoothpractice.AAChartCoreLib.AAChartCreator.AAChartModel;
import com.lzw.bluetoothpractice.AAChartCoreLib.AAChartCreator.AAChartView;
import com.lzw.bluetoothpractice.AAChartCoreLib.AAChartCreator.AASeriesElement;
import com.lzw.bluetoothpractice.AAChartCoreLib.AAChartEnum.AAChartType;
import com.lzw.bluetoothpractice.AAChartCoreLib.AAOptionsModel.AADataElement;
import com.lzw.bluetoothpractice.AAChartCoreLib.AAOptionsModel.AAMarker;
import com.lzw.bluetoothpractice.AAChartCoreLib.AAOptionsModel.AAScrollablePlotArea;
import com.lzw.bluetoothpractice.AAChartCoreLib.AATools.AAGradientColor;
import com.lzw.bluetoothpractice.AAChartCoreLib.AATools.AALinearGradientDirection;
import com.lzw.bluetoothpractice.MyApplication;
import com.lzw.bluetoothpractice.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AngleActivity extends BaseActivity {

    private AAChartView aaChartViewAngle;
    private Object[] array;
    private Handler mHander=new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_angle);
        InitNavBar(true,"屈膝度",false);

        aaChartViewAngle = findViewById(R.id.AAChartViewAngle);
        aaChartViewAngle.aa_drawChartWithChartModel(arearangeMixedLine());
       // mHander.post(timeRunable);
    }

  /*  private Runnable timeRunable = new Runnable() {
        @Override
        public void run() {
            List<Object> list= new ArrayList<Object>(MyApplication.getInstance().angle);
            array = (Object[])list.toArray(new Object[list.size()]);
            AASeriesElement[] aaSeriesElements=new AASeriesElement[]{
                    new AASeriesElement()
                            .data(array)
            };




            aaChartViewAngle.aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(aaSeriesElements);


            mHander.postDelayed(this, 1000);

        }

    };*/
    AAChartModel arearangeMixedLine() {

        AADataElement singleSpecialData1 = new AADataElement()
                .marker(new AAMarker()
                        .fillColor("#D81B60")
                        .lineColor("#D81B60")//外沿线的颜色(用来设置折线连接点的轮廓描边颜色，当值为空字符串时，默认取数据点或数据列的颜色)

                )
                .color("#D81B60")
                .y(39.5f);
        Map linearGradientColor = AAGradientColor.linearGradient(
                AALinearGradientDirection.ToBottom,
                "rgba(212,233,253,1)",
                "rgba(254,254,254,0)"
        );



        AASeriesElement element1 = new AASeriesElement()
                .name("屈膝度")
                .fillColor(linearGradientColor)
                .data(array)
                ;


        /* 37.5, 36.3,36.2,36.8,36.7,36.5,37.1,37.2,37.5,36.9,36.8,36.4,36.5,36.5
                    ,35.9,35.8,35.6,36.1,36.5,36.9,37.1,37.5,37.6,37.8,38.1,37.1,37.5,38.1,38.2,38.6,
                    36.9,36.8,36.7,36.5,36.2,35.1,35.4,36.8,36.9,37.5,37.6,37.9,38.6,singleSpecialData1,38.9
                    ,38.4,37.9,38.9,singleSpecialData1,singleSpecialData1,38.1,37.9,37.5,37.2,37.5, 36.3,36.2,36.8,36.7,36.5,37.1,37.2,37.5,36.9,36.8,36.4,36.5,36.5
                                ,35.9,35.8,35.6,36.1,36.5,36.9,37.1,37.5,37.6,37.8,38.1,37.1,37.5,38.1,38.2,38.6,
                                36.9,36.8,36.7,36.5,36.2,35.1,35.4,36.8,36.9,37.5,37.6,37.9,38.6,singleSpecialData1,38.9
                                ,38.4,37.9,38.9,singleSpecialData1,singleSpecialData1,38.1,37.9,37.5,37.2*/

        return new AAChartModel()
                .chartType(AAChartType.Areaspline)
                .yAxisMax(180.0f)
                //y轴最小值
                .yAxisMin(0.0f)
                .dataLabelsEnabled(true)
                .yAxisLabelsEnabled(true)
                .xAxisLabelsEnabled(false)
                .gradientColorEnable(true)
                .title("")
                .yAxisTitle("")
                .legendEnabled(false)
                .yAxisGridLineWidth(0f)
                .scrollablePlotArea(
                        new AAScrollablePlotArea()
                                .minWidth(500)
                                .scrollPositionX(1f)
                )
                .series(new AASeriesElement[]{element1});
    }
}
